import { axiosInstance } from 'src/boot/axios'
import CommonConfig from 'src/assets/js/config'

const baseUrl = CommonConfig.miotUrl + '/v1'

/**
 * 获取产品型号
 */
export function getLteInfo (boxId) {
  const newUrl = baseUrl + `/box/lte_info/${boxId}`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

export function restartBox (boxId) {
  const newUrl = baseUrl + `/box/restart?boxId=${boxId}`

  return axiosInstance.post(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

export function resetBox (boxId) {
  const newUrl = baseUrl + `/box/sub_clear?boxId=${boxId}`

  return axiosInstance.post(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

export function appVersionCompare (params) {
  const newUrl = baseUrl + `/box/app_version_compare`

  return axiosInstance.get(newUrl, { params }).then((res) => {
    return Promise.resolve(res)
  })
}

export function driverVersionCompare (params) {
  const newUrl = baseUrl + `/box/driver_version_compare`

  return axiosInstance.get(newUrl, { params }).then((res) => {
    return Promise.resolve(res)
  })
}

export function driverUpdate (params) {
  const newUrl = baseUrl + `/box/sub_device_update_direct`

  return axiosInstance.post(newUrl, params).then((res) => {
    return Promise.resolve(res)
  })
}

export function appUpdate (boxId, fileUrl) {
  const newUrl = baseUrl + `/box/app_update?boxId=${boxId}&fileUrl=${fileUrl}`

  return axiosInstance.post(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

export function getShadow (boxId) {
  const newUrl = baseUrl + `/box/shadow/${boxId}`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

export function subDeviceDel (boxId, deviceNum) {
  const newUrl = baseUrl + `/box/sub_device_del?boxId=${boxId}&deviceNum=${deviceNum}`

  return axiosInstance.delete(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

export function runningState (boxId) {
  const newUrl = baseUrl + `/box/running_state?boxId=${boxId}`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 盒子新增子设备
 */
export function deviceBindBoxSub (params) {
  const newUrl = baseUrl + `/device/bind_box_sub`

  return axiosInstance.post(newUrl, params).then((res) => {
    return Promise.resolve(res)
  })
}

/**
 * 检查盒子是否在线
 */
export function checkOnlineStatus (assetNum) {
  const newUrl = baseUrl + `/device/online_status/${assetNum}`

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}
